<template>
	<view class="main">
		<view class="br-top v-box dis-row">
			<view class="poser-index poser" :class="{'psvActive':current == navindex}" v-for="(navitem,navindex) in tabLiast" :key="navindex" @click="checkClick(navitem,navindex)">
				{{navitem.name}}<label v-if="current == navindex"></label>
			</view>
		</view>
		<!--好活开始-->
		<block v-if="current == 0">
			<block v-if="glanceList.length>0">
			<!--list type1 start-->
			<!-- <view class="inter-item" v-for="(item,index) in glanceList" :key="index"> -->
				<JobItem v-for="(item,index) in glanceList" :key="index" :data="item"
					@jobItemClick="jobItemClick"></JobItem>
			<!-- </view> -->
			<!--list type1 over-->	
			</block>
			<block v-if="glanceList.length == 0">
				<view class="empty-img">
					<image src="http://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/icon50.png"></image>
					<label>暂无内容</label>
				</view>
			</block>
		</block>
		<!--好活结束-->
		<!--师傅端信息开始-->
		<block v-if="current == 1">
			<block v-if="workerList.length>0">
			<!--list start-->
			<view class="master-block" v-for="(bditem,bdindex) in workerList" :key="bdindex" @click="jumpNav(bditem)">
				<view class="master-item">
					<view class="master-faceItem poser dis-row">
						<!--头像处理start-->
						<view class="faceItem-ico poser">
							<image :src="bditem.avatar?bditem.avatar:'http://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/1.jpg'"></image>
							<label>个人</label>
						</view>
						<!--头像处理over-->
						<!--顶部右侧标题文字开始-->
						<view class="faceText dis-clm">
							<!--置顶信息start-->
							<view class="faceText-t1 dis-row">
								<!-- <view class="zhidding">置顶</view> -->
								<view class="master-name">{{bditem.nickName?bditem.nickName:'天下工人'}}</view>
								<block v-if="bditem.isRealName == 1">
									<label><image src="http://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/user-real.svg"></image></label>
									<text>实名认证</text>
								</block>
							</view>
							<!--置顶信息over-->
							<view class="master-userinfo dis-row">
								{{bditem.gender==1?'男':'女'}}<text>|</text>{{bditem.age?bditem.age:0}}岁<text>|</text>{{bditem.nationStr?bditem.nationStr:'汉族'}}
							</view>
						</view>
						<!--顶部右侧标题文字结束-->
						<!--是否在线开始-->
						<view class="master-t3 dis-row" v-if="item.status">
							<view><label></label></view><text>今日找活中</text>
						</view>
						<!--是否在线结束-->
					</view>
					<!--标签列表开始-->
					<view class="bloc-small">
					<!-- 	<label class="noactive">{{bditem.salaryStr}}{{bditem.salaryStr}}</label> -->
						<!-- <label>日结</label>
						<label>包吃包住</label>
						<label>高温补贴</label>
						<label>医疗保险</label> -->
						<label v-if="bditem.workYear">{{bditem.workYear}}年工龄</label>
						<label v-if="bditem.workType1Str">{{bditem.workType1Str}}</label>
						<label v-if="bditem.masteryStr">{{bditem.masteryStr}}</label>
					</view>
					<view class="block-pre" style="color: #A1A1A1;font-size: 28rpx;">{{bditem.notice}}</view>
					<!--标签列表结束-->
					<!--底部开始哦-->
					<view class="master-zpList dis-clm poser">
						<view class="zpList-child dis-row">
							<label>期望工种</label><text>{{bditem.skills?strHandle(bditem.skills,','):'/'}}</text>
						</view>
						<view class="zpList-child dis-row">
							<label>期望地点</label><text>{{bditem.hopeAddr?strHandle(bditem.hopeAddr,','):'/'}}</text>
						</view>
						<view class="zpList-right dis-clm"> 
							<view class="zplistrv-s1"><label>{{bditem.salary?bditem.salary:0}}</label>{{bditem.salaryUnitStr?bditem.salaryUnitStr:'元/月'}}</view>
							<view class="zpList-s2">期望薪资</view>
						</view>
					</view>
					<!--底部结束-->
				</view>
			</view>
			<!--list over-->
			</block>
			<block v-if="workerList.length ==0">
				<view class="empty-img">
					<image src="http://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/icon50.png"></image>
					<label>暂无内容</label>
				</view>
			</block>
			
			
			
		</block>
		<!--师傅端信息结束-->
	</view>
</template>

<script>
	//浏览页面
import Index from "@/common/index-model.js"	
import fun from '@/common/publicFun.js'
let index = new Index()
let that = null
export default {
	data(){
		return {
			tabLiast:[
				{name:'好活'},
				{name:'师傅'}
			],
			current:0,
			glanceList:[],
			workerList:[]
		}
	},
	onLoad() {
		this.getworks()
	},
	methods: {
		jobItemClick(data) {
			console.log('你点到我了～～～小心点', data)
			uni.navigateTo({
				url: "/pagesB/jobinfo/jobLeavetwoInfo?cardID=" + data.data.id
			})
			uni.setStorage({
				key: 'cardID',
				data: data.data.id,
				success: () => {
					console.log('存入成功')
				}
			})
		},
		strHandle(str,char=','){
			str=index.strTrim(str,char);
			return index.strRep(str,',','、');
		},
		checkClick(item,index) {
			this.current = index
			if(index==0){
				// this.getglanceList()
					this.getworks()
			}else{
				this.getWorkList()
			}
		},
		jumpNav(item) {
			index.navigate_to('../../pagesB/workInfo/RecruitmentInfo?id='+item.id)
		},
		//获取浏览的列表
		getglanceList() {
			let send={
				"time":this.timestampToTime()
			}
			index.getPublicUserMember(send,'client/individual/find/browse','post',res=>{
				let arr= [],welfares=[]
				this.glanceList = []
				if(res.data.code==200 && res.data.success){
					// this.glanceList = res.data.result
					arr = res.data.result
					if(arr.length>0){
					  for(let i=0;i<arr.length;i++){
					  //	arr[i].titleName = arr[i].address+'招'+arr[i].skills  //拼接地址+技能 = 列表标题
						if(arr[i].welfare){
							welfares=arr[i].welfare.split(',');
							for(let i=0;i<welfares.length;i++){
								if(welfares[i] == ''){
									welfares.splice(i,1)
								}
							}
							arr[i].welfareNew = welfares;
							//arr[i].welfareNew = arr[i].welfare.split(',')
						}else{
							arr[i].welfareNew = []
						}
						this.glanceList.push(arr[i])
					  }
					}
				}else{
					this.glanceList =[]
				}
			})
		},
		getworks(){
			index.getPublicUserMember({
				pageSize:100,
				pageIndex:0
			},'client/recuitjob/myblist','get',res=>{
				if(res.data.code == 200 && res.data.success){
					this.glanceList = res.data.result.records
				}else{
					this.glanceList = []
				}
			})
		},
		//获取师傅数据
		getWorkList() {
			let send={
				"lastTime":this.timestampToTime()
			}
			index.getPublicUserMember(send,'client/individual/find/browseCard','post',res=>{
				if(res.data.code == 200 && res.data.success){
					this.workerList = res.data.result
				}else{
					this.workerList = []
				}
			})
		},
		timestampToTime() {
				var date = new Date();//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				var Y = date.getFullYear()+'-';
				var M = (date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1)+'-';
				var D = date.getDate()<10?('0'+date.getDate()+' '):(date.getDate()+' ');
				var h = date.getHours()<10?('0'+date.getHours()+':'):(date.getHours()+':');
				var m = date.getMinutes()<10?('0'+date.getMinutes()+':'):(date.getMinutes()+':');
				var s = date.getSeconds()<10?('0'+date.getSeconds()):(date.getSeconds());
				// var m = date.getMinutes() + ':';
				// var s = date.getSeconds();
			    return Y+M+D+h+m+s;
		},
		cutstr(str, len) {
			var str_length = 0;
			var str_len = 0;
			var str_cut = new String();
			str_len = str.length;
			for (var i = 0; i < str_len; i++) {
				var a = str.charAt(i);
				str_length++;
				if (escape(a).length > 4) {
					//中文字符的长度经编码之后大于4  
					str_length++;
				}
				str_cut = str_cut.concat(a);
				if (str_length >= len) {
					str_cut = str_cut.concat("...");
					return str_cut;
				}
			}
			//如果给定字符串小于指定长度，则返回源字符串；  
			if (str_length < len) {
				return str;
			}
		},
		NavOrderinfo(item) {
		   if(item.orderId){
			   let url="../../pagesB/jobinfo/index?id="+item.orderId
			   index.navigate_to(url)
		   }else{
			   index.show_tips('缺少项目id')
			   return false
		   }
		},
		times(time,char){
			return fun.formatDate(time,char);
		},
		timeF(time,char){
			let d = new Date(time);
			let t = d.getTime(d) // 方法1
			return fun.formatDate(t,char);
		},
	}
}
</script>
<style>
	page{
		width: 100%;height: 100%;background-color: #efefef;
	}
</style>
<style scoped>
@import url("@/static/css/publics.css");	
@import url("@/static/css/mybrowse.css");
@import url("@/static/css/myBeInterested.css");	
</style>